//
//  FoundTableViewController.m
//  UI13_homework(简书)
//
//  Created by Hanlingyu on 16/8/1.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "FoundTableViewController.h"
#import "LTQCycleImages.h"
#import "FoundTableViewCell.h"
#import "FoundModal.h"
#define kTableViewReuse @"reuse"
@interface FoundTableViewController ()
@property (strong, nonatomic) IBOutlet UITableView *foundTableView;
@property (weak, nonatomic) IBOutlet LTQCycleImages *cycleImages;
@property (nonatomic, strong) NSMutableArray *arr;
@end

@implementation FoundTableViewController


- (void)handleData {
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Source.plist" ofType:nil];
    NSArray *arr = [NSArray arrayWithContentsOfFile:path];
    self.arr = [NSMutableArray array];
    for (NSDictionary *dict in arr) {
        FoundModal *model = [[FoundModal alloc] init];
        [model setValuesForKeysWithDictionary:dict];
        [self.arr addObject:model];
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    
//    [_foundTableView registerClass:[FoundTableViewCell class] forCellReuseIdentifier:kTableViewReuse];
    [self handleData];
    NSArray *array = @[@"guidePage_01", @"guidePage_02", @"guidePage_03", @"guidePage_04"];
    [_cycleImages setImagesWithArray:array];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _arr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"1");
    FoundTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewReuse forIndexPath:indexPath];
    FoundModal *found = _arr[indexPath.row];
    cell.contentLabel.text = found.title;
    [cell.sourceButton setTitle:found.source forState:UIControlStateNormal];
    cell.countLabel.text = @"阅读3104 * 评论7 * 喜欢86";
    [cell.userNameButton setTitle:found.name forState:UIControlStateNormal];
    cell.timeLabel.text = found.time;

    NSLog(@"%@", cell);
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
//    NSLog(@"2");
    
    FoundTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    CGFloat height = cell.timeLabel.frame.size.height + cell.contentLabel.frame.size.height + cell.userHeaderImage.frame.size.height + 30;
    
    return height;
    
    
    
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
